<script lang="ts" setup>
import type { UploadFile } from "element-plus"
import { Delete, Plus, ZoomIn } from "@element-plus/icons-vue"
import { ref } from "vue"

const dialogImageUrl = ref("")
const dialogVisible = ref(false)
const disabled = ref(false)

const fileList = ref<UploadFile[]>([])

function handleRemove(file: UploadFile) {
  console.log(file)
}

function handlePictureCardPreview(file: UploadFile) {
  dialogImageUrl.value = file.url!
  dialogVisible.value = true
}
defineExpose({
  fileList
})
</script>

<template>
  <el-upload action="#" list-type="picture-card" :auto-upload="false" v-model:file-list="fileList">
    <template #file="{ file }">
      <div>
        <img class="el-upload-list__item-thumbnail" :src="file.url" alt="">
        <span class="el-upload-list__item-actions">
          <span
            class="el-upload-list__item-preview"
            @click="handlePictureCardPreview(file)"
          >
            <el-icon><ZoomIn /></el-icon>
          </span>

          <span
            v-if="!disabled"
            class="el-upload-list__item-delete"
            @click="handleRemove(file)"
          >
            <el-icon><Delete /></el-icon>
          </span>
        </span>
      </div>
    </template>
    <el-icon><Plus /></el-icon>
  </el-upload>

  <el-dialog v-model="dialogVisible">
    <img w-full :src="dialogImageUrl" alt="Preview Image" width="500px" height="500px">
  </el-dialog>
</template>

<style lang="scss">

</style>
